#coding:utf-8
from django.contrib import admin
from lovewith.supplier.models import ServiceCate, Supplier


#商家服务分类
class ServiceCateAdmin(admin.ModelAdmin):
    list_display = ('id', 'stage', 'name', 'cate', 'sort')
    ordering = ('sort',)
    #
    list_filter = ('stage', 'name', 'cate',)


#服务商列表
class SupplierAdmin(admin.ModelAdmin):
    list_display = ('id', 'info_company', 'address', 'name', 'tel', 'phone', 'qq', 'info_enable', 'score')
    ordering = ('-id',)
    search_fields = ('company',)
    list_filter = ('enable',)
    #只读字段
    readonly_fields = ('city', 'user', 'join_date')
    #分页
    list_per_page = 50

    #商家名称
    def info_company(self, obj):
        return '<a href="/su/join/?uid=%s" target="_blank" title="点击查看提交的服务商资料">' \
               '%s</a>' % (obj.user_id, obj.company)
    info_company.short_description = '公司名称'
    info_company.allow_tags = True

    #是否已审核
    def info_enable(self, obj):
        if obj.enable == 1:
            return '<img src="/static/admin/img/icon-yes.gif" />'
        if obj.enable == -1:
            return '<img src="/static/admin/img/icon-no.gif" />'
        if obj.enable == 0:
            return '未审核'
    info_enable.short_description = '是否已审核通过'
    info_enable.allow_tags = True

    #inlines = [SupplierServiceInline,]

#注册显示model
#admin.site.register(ServiceCate, ServiceCateAdmin)
admin.site.register(Supplier, SupplierAdmin)